import os
from channels.channels import Channel

class ReadDir2Lines(Channel):
    required = ['file_dir']
    send = ['lines']
    
    @staticmethod
    def execute(args={}, meta={}, lines=[], **kwargs):
        file_dir = args.file_dir
        new_lines = []

        for dir_name, _, file_names in os.walk(file_dir):
            for file_name in file_names:
                file_path = os.path.join(dir_name, file_name)
                with open(file_path, 'r', encoding='utf-8') as fr:
                    lines = fr.readlines()
                    new_lines.extend(lines)

                # bar show
                args.false_bar()
                print(file_path, 'has been coverted!')

        return {
            'lines': new_lines
        }
        